# coding=utf-8

from selenium import webdriver

from ..common.read_config import edge_driver



class BasePage(object):
    def __init__(self,driver=None):
        if driver is None:
            opt = webdriver.EdgeOptions()
            # 页面加载策略
            opt.page_load_strategy = 'eager'
            # 启用无头模式
            # opt.add_argument('--headless')  
            # 禁用插件
            opt.add_argument('--disable-extensions')
            # 打开浏览器不关闭
            # opt.add_experimental_option("detach", True)
            # opt.add_argument("disable-infobars")
            # opt.add_experimental_option('useAutomationExtension', False)
            # opt.add_experimental_option("excludeSwitches", ['enable-automation'])
            # opt.add_experimental_option("prefs", {"credentials_enable_service": False,
            #                                              "profile.password_manager_enabled": False,
            #                                              "profile.default_content_setting_values.notifications": 2})
            service = webdriver.EdgeService(executable_path=edge_driver)
            self.driver = webdriver.Edge(options=opt,service=service)
            self.driver.maximize_window()
        else:
            self.driver = driver
        
       
        
    def open_page(self,url):
        self.driver.get(url)
        
    
    def quit_driver(self):
        return self.driver.quit()
        
    def find_element(self,locator,locator_content):
        return self.driver.find_element(locator,locator_content)
        
    def find_elements(self,locator,locator_content):
        return self.driver.find_elements(locator,locator_content)
        
    def switch_alert(self):
        return self.driver.switch_to.alert